/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Threads;

import edu.wpi.first.wpilibj.SerialPort;
import edu.wpi.first.wpilibj.visa.VisaException;
import ticks.chromedome.commands.CommandBase;

/**
 *
 * @author Jared
 */
public class ArduinoSerial implements Runnable {
    private static ArduinoSerial instance=null;
    private SerialPort serial;
    private int R, G, B;
    
    
    public static ArduinoSerial getInstance(){
        if(instance==null){
            instance = new ArduinoSerial();
        }
        return instance;
    }
    
    private ArduinoSerial(){
        try {
            serial = new SerialPort(9600);
        } catch (VisaException ex) {
            
        }
        new Thread(this).start();
    }
    
    public void run(){
        while(true==true){
        R=CommandBase.robot_global.getLights()[0];
        G=CommandBase.robot_global.getLights()[1];
        B=CommandBase.robot_global.getLights()[2];
        
        try {
            serial.print(Integer.toString(R)+","+Integer.toString(G)+","+Integer.toString(B) + '\n' );
            
        } catch (VisaException ex) {
            
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException ex) {
            
        }
    }
    
}}
